//---------------------------------------------------------------------------
#ifndef DPCnsMCIH
#define DPCnsMCIH

//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "DialPad.h"
#include "PHDS.h"
#include <ExtCtrls.hpp>
#include <Buttons.hpp>
#include "PHEdit.h"
#include "PHLabel.h"
#include "PHGridEd.h"
#include <Grids.hpp>
#include "stdm.h"
#include "PHSpdBut.h"
#include "PHCheck.h"
#include "PHGrid.h"
#include "Emissao.h"
#include "Word_2K_SRVR.h"
#include <OleServer.hpp>
#include "DIALPAD.h"
//---------------------------------------------------------------------------
class TDPCnsMCI1 : public TDiPad
{
  __published:  // IDE-managed Components
    TBitBtn*  BitBtn1;
    TBitBtn*  BitBtn3;
    PHLabel*  PHLabel1;
    PHEdit*  PHEdit1;
    PHLabel*  PHLabel2;
    PHEdit*  PHEdit2;
    PHGridEdit*  PHGridEdit1;
    PHDataSource*  DSCli;
    TBitBtn*  BitBtn2;
    TBitBtn*  BitBtn4;
    PHCheckBox*  PHCheckBox1;
 TGroupBox *GroupBox1;
 TLabel *Label1;
 TBevel *Bevel2;
 PHCheckBox *PHCheckBox2;
 TBitBtn *BtnRecibo;
 TWordApplication *Wapp;
 TWordDocument *WordDoc;
 TLabel *Label2;
 PHDataSource *DSRcbto;
 PHCheckBox *PHCheckBox3;
    void __fastcall BitBtn3Click( TObject* Sender );
    void __fastcall DSCliAfterOpen( TObject* Sender );
    void __fastcall BitBtn1Click( TObject* Sender );
    void __fastcall FormDestroy( TObject* Sender );
    void __fastcall BitBtn4Click( TObject* Sender );
    void __fastcall PHEdit1Change( TObject* Sender );
    void __fastcall PHEdit2Change( TObject* Sender );
    void __fastcall PHCheckBox1Click( TObject* Sender );
    void __fastcall PHGridEdit1DrawGridCell( int Row, int Col, TColor&  CorTexto, TColor&  CorFundo,
                                             bool&  AplicarCoresSelecao, PHDataSource*  PHDS,
                                             AnsiString&  Conteudo );
    void __fastcall FormShow( TObject* Sender );
    void __fastcall PHGridEdit1DblClick( TObject* Sender );
    void __fastcall FormClose( TObject* Sender, TCloseAction& Action );
    void __fastcall PHGridEdit1KeyDown( TObject* Sender, WORD& Key, TShiftState Shift );
 void __fastcall PHCheckBox2Click(TObject *Sender);
 void __fastcall BtnReciboClick(TObject *Sender);
 void __fastcall WappQuit(TObject *Sender);
 void __fastcall DSRcbtoAfterOpen(TObject *Sender);
 void __fastcall PHCheckBox3Click(TObject *Sender);
        void __fastcall PHEdit1Exit(TObject *Sender);

  private:
    enum TipoReg{trCliente,trSaldoAnterior,trFaturamento,trDetFat,trDetFatRet,
                                           trRecebimento,trDetRec,trDetRecRet,trTotalizador};
    struct CFGERAL *GR;
    struct FAT *Fat;
    struct RCBTO *Rct;
    struct MVCTR *MvCtr;
    TLista *LCli;
    TStringList *MovCli;
    TStringList *ListaCli;
    TStringList *ListaFat;
    TEmissao *Emissao;
    bool Prim;
    bool MultasEJuros;
    PHDataSource *DSMvCtr;
    int MesesAtraso;
    int DiasAtraso;
    //  Classe que armazena o movimento do cliente
    class MOVCLI : TObject
    {
      public: AnsiString Cliente;
        int Data;
        int DataRecebimento;
        AnsiString Documento;
        AnsiString Historico;
        int Vencimento;
        bool Faturamento;
        double Valor;
        double ValorPago;
        double Credito;
        double CreditoUtilizado;
        double JurosMulta;
        double Descontos;
        int Lancamento;
        int LancamentoFat;
        int Mes;
        int Ano;
        bool PagoMaior;
    } *MC;
    void __fastcall Processamento( TObject* Sender );
    void __fastcall TDPCnsMCI1::DetalhesFaturamento(int Ano, int Mes, int Lancamento,
                                                    AnsiString CodCli, unsigned DataEmissao);
    void __fastcall DetalhesRecebimento(int Data, int LcmentoFat,AnsiString Cliente,unsigned long Data2);
    void __fastcall ProcessaSaldoAnterior(void);
    void __fastcall ProcessaLancamentos(unsigned long Data1, unsigned long Data2);
    void __fastcall ProcessaFaturamento(unsigned long DataInicial, unsigned long DataFinal);
    void __fastcall ProcessaRecebimentos(int DataInicio , int DataFim);
    void __fastcall InsereNomeClientes(void);
    void __fastcall ProcessaSaldos(void);
    bool __fastcall ProcessaValoresAbertos(unsigned long MesAno, double &SaldoFat);
    void __fastcall ProcessaSaldoAnteriorComMultasJuros(void);
    double __fastcall ProcessaJuros(unsigned long DataFaturado);
    bool __fastcall PermiteIncluirRecebimento(PHDataSource  *DS, AnsiString MesAno, int Lancamento, unsigned long DataSaldo);
    AnsiString GE;

  public:
    void __fastcall LimpaGrid( void );
    __fastcall TDPCnsMCI1( TComponent* Owner );
    struct MVCL*  Cl;
    bool Alterar;
    char TipoAlterar;
    int DataAlterar;
    int LancamentoAlterar;
    int Data;
    int TipoModelo;
};
//---------------------------------------------------------------------------
extern PACKAGE TDPCnsMCI1*  DPCnsMCI1;
//---------------------------------------------------------------------------
#endif

